//
//  JYJSechContentSegmentCollectionViewCell.m
//  HappyListen
//
//  Created by 冀永金 on 16/9/9.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJSechContentSegmentCollectionViewCell.h"
#import "BaseCollectionView.h"
#import "JYJTAMacro.h"
#import "JYJSechContentSegmentCollectionViewCellTwo.h"
@interface JYJSechContentSegmentCollectionViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong)BaseCollectionView *collection;
@property (nonatomic, strong)UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) UISegmentedControl *segment;
@end
@implementation JYJSechContentSegmentCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
        [self createSegmentController];
    }
    return self;
}
- (void)createSubViews {
    _layout = [[UICollectionViewFlowLayout alloc]init];
    _layout.minimumLineSpacing = 0;
    _layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collection = [[BaseCollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:_layout];
    [self.contentView addSubview:_collection];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    [self.collection registerClass:[JYJSechContentSegmentCollectionViewCellTwo class] forCellWithReuseIdentifier:@"pool"];
    self.collection.scrollEnabled = NO;
}
- (void)createSegmentController {
    self.segment = [[UISegmentedControl alloc]initWithItems:@[@"最新播放",@"最多播放"]];
    self.segment.selectedSegmentIndex = 0;
    [self.contentView addSubview:_segment];
    self.segment.tintColor =[UIColor colorWithRed:0.24 green:0.25 blue:0.31 alpha:1.00];
    [_segment setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.collection.frame = CGRectMake(0, 42, SCREEN_WIDTH, SCREEN_HEIGHT - 85);
    _layout.itemSize = CGSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT - 85);
     self.segment.frame = CGRectMake(0, 0, SCREEN_WIDTH, 40);
    [self.segment addTarget:self action:@selector(handle:) forControlEvents:UIControlEventValueChanged];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    JYJSechContentSegmentCollectionViewCellTwo *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    cell.inputWord = self.inputWord;
    cell.index = indexPath.item;
    cell.handleNext = self.handleNext;
    return cell;
}
- (void)handle:(UISegmentedControl *)seg{
    switch (seg.selectedSegmentIndex) {
        case 0:
            self.collection.contentOffset = CGPointMake(0, 0);
            break;
            case 1:
            self.collection.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
            break;
        default:
            break;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
